package com.wing.portal.aggregation.portletinfo;

import java.util.HashMap;
import java.util.Map;

import org.springframework.stereotype.Service;

import com.wing.cms.domain.Portlet_C;
import com.wing.cms.ext.domain.CustomPortletInerface;
import com.wing.cms.service.Portlet_CManager;
import com.wing.common.util.SpringDI;
import com.wing.ext.service.ProductsManager;

@Service
public class CustomPortletInfo implements PortletInfo {
	
	/**
	 * 通过portletId查找模板位置
	 * 
	 * @param portletId 
	 * @return templateFilePath
	 */

	public String findTemplateFile(String portletId) {
		Portlet_CManager portletInstance1Manager = (Portlet_CManager) SpringDI
				.getBean("portlet_CManager");
		return portletInstance1Manager.findTemplateFile(portletId);
	}

	public Map loadPortletInfo(Map<String, String> param) {
		Map root = new HashMap();
		String portletId = param.get("portletid");
		String siteId = param.get("siteId");
		Portlet_CManager portletInstanceManager = (Portlet_CManager) SpringDI
				.getBean("portlet_CManager");
		ProductsManager productsManager = (ProductsManager) SpringDI
		.getBean("productsManager");
		
		Portlet_C portletInfo = portletInstanceManager.findById(portletId);
		if(portletInfo==null){
			root.put("portletWidth", 40);
			root.put("portletheight", 10);
			return root;
		}
		CustomPortletInerface cp;
		try {
			cp = portletInfo.getObjectView();
			root.putAll(cp.getMaps());
		} catch (Exception e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		root.put("title", portletInfo.getTitle());
		root.put("titlecolor", portletInfo.getTitlecolor());
		root.put("titletype", portletInfo.getTitletype()==null?"0":portletInfo.getTitletype());
		root.put("titlepic", portletInfo.getTitlepic());
		root.put("portletWidth", portletInfo.getPortletwidth());
		root.put("portletheight", portletInfo.getPortletheight());
		
		return root;
	}
	
	
}
